﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Telerik.Web.UI;
using System.Data;
using System.Web.Security;

namespace ProjectSem40701.Admin
{
    public partial class SubjectAdd : System.Web.UI.Page
    {
        private const string SUCCESS = "success";
        private const string FAIL = "fail";

        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnAdd_Click(object sender, EventArgs e)
        {
            try
            {
                AdminXSD.SubjectTableAdapters.tbl_SubjectTableAdapter dp = new AdminXSD.SubjectTableAdapters.tbl_SubjectTableAdapter();
                int ok = dp.tbl_Subject_Insert(this.txtSubjectName.Text.Trim(), Server.HtmlEncode(this.txtContent.Value.Trim()), Convert.ToInt32(this.cbbSubjectStatus.SelectedValue.Trim()));

                if (ok > 0)
                {
                    Show_Dialog(SUCCESS);
                }
                else
                {
                    Show_Dialog(FAIL);
                }
            }
            catch
            {
                Show_Dialog(FAIL);
            }
        }
        private void Close_Dialog()
        {
            switch (this.lblSuccess.Text)
            {
                case SUCCESS:
                    Response.Redirect("Subject.aspx");
                    break;
                case FAIL:
                    this.btnAdd_ModalPopupExtender.Enabled = false;
                    Response.Redirect("Subject.aspx");
                    break;
                default:
                    this.btnAdd_ModalPopupExtender.Enabled = false;
                    break;
            }
        }
        private void Show_Dialog(String Check)
        {
            switch (Check)
            {
                case SUCCESS:
                    this.ltrMessage.Text = "Thành công";
                    break;
                case FAIL:
                    this.ltrMessage.Text = "Thất bại";
                    break;
                default:
                    this.ltrMessage.Text = "Không thành công";
                    break;
            }
            this.lblSuccess.Text = Check;
            this.btnAdd_ModalPopupExtender.Enabled = true;
            this.btnAdd_ModalPopupExtender.Show();
        }
        protected void btnClose_Click(object sender, EventArgs e)
        {
            Close_Dialog();
        }

        protected void btnYes_Click(object sender, EventArgs e)
        {
            Close_Dialog();
        }
    }
}
